<%@page import="java.net.URLEncoder"%>
<%@ page import="java.util.*" %>
<%
	String fid = request.getParameter("fid");
	String toUrl = request.getParameter("tourl");
	long userid = 0l;
	//if(UserCookieUtil.getUserId(request)!=null){ 
		//userid=UserCookieUtil.getUserId(request);

/**
这段代码的作用就是从session中获得user是否登陆过
		if(RigthSrv.getUserRightsId(request, response)!=null){
		try{
			userid=Long.parseLong(RigthSrv.getUserRightsId(request, response));
	//	userid=7969523l;
			String loginName=RigthSrv.getUserLoginName(request, response);
			if(loginName!=null && loginName.length()>0 && loginName.startsWith("t_netease_")){
				userid=0l;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	*/
	
	if (toUrl == null || toUrl.equals("")) {
		toUrl = request.getRequestURI();
		if (toUrl == null || toUrl.equals(""))
			toUrl = "";
		else {
			Map f = request.getParameterMap();
			Set s = f.keySet();
			String g = "?";
			for (Iterator i = s.iterator(); i.hasNext();) {
				String h = (String) i.next();
				String j = request.getParameter(h);
				g += h + "=" + j + "&";
			}
			g = g.substring(0, g.length() - 1);
			toUrl += g;
		}
	}
	try {
		if (userid <= 0) {
			String rurl = "https://passport.lefeng.com/login.jsp?tourl=" + URLEncoder.encode("http://order.lefeng.com" + toUrl, "utf-8");
			if (fid != null) {
				rurl += "?fid=" + fid;
			}
			response.sendRedirect(rurl);
			return;
		}
	} catch (Exception e) {
		String rurl = "https://passport.lefeng.com/login.jsp?tourl=" + URLEncoder.encode("http://order.lefeng.com" + toUrl, "utf-8");
		if (fid != null) {
			rurl += "?fid=" + fid;
		}
		System.out.println("validate_login.jsp error exception:"+e.getMessage());
		response.sendRedirect(rurl);
		return;
	}
%>
<%!
	private static Map<String,String> pageMap=new HashMap<String,String>();
	private static Map<String,String> keyMap=new HashMap<String,String>();
	private static Map<String,String> hashKeyMap=new HashMap<String,String>();
	static{
		pageMap.put("/card/queryBindingCard.jsp","0");
		pageMap.put("/card/bindCard.jsp","0");
		pageMap.put("/card/myCard.jsp","0");
		pageMap.put("/my_lafaso.jsp","0");
		pageMap.put("/user_orders.jsp","0");
		pageMap.put("/myvouchers.jsp","0");
		pageMap.put("/center/list.jsp","0");
		pageMap.put("/redbag/redbagList.jsp","0");
		pageMap.put("/re_user_orders.jsp","0");
		keyMap.put("0", "k");
		keyMap.put("1", "i");
		keyMap.put("2", "c");
		keyMap.put("3", "1");
		keyMap.put("4", "p");
		keyMap.put("5", "5");
		keyMap.put("6", "q");
		keyMap.put("7", "8");
		keyMap.put("8", "s");
		keyMap.put("9", "3");
		
		hashKeyMap.put("0", "y");
		hashKeyMap.put("1", "0");
		hashKeyMap.put("2", "e");
		hashKeyMap.put("3", "6");
		hashKeyMap.put("4", "o");
		hashKeyMap.put("5", "c");
		hashKeyMap.put("6", "z");
		hashKeyMap.put("7", "2");
		hashKeyMap.put("8", "u");
		hashKeyMap.put("9", "d");
		  
	}
	
	public static String confuseUid(long uid){
		StringBuffer rStr=new StringBuffer("");
		String str=String.valueOf(uid);
		int len=str.length();
		int c=len/2;
		String re=String.valueOf(uid).substring(len-c, len-c+1);
		String[] sp=String.valueOf(uid).split(re);
		long b=0l;
		for(int i=0;i<sp.length;i++){
			if(!sp[i].equals("")){
				b=b+Long.parseLong(sp[i]);
			}
		}
		for(int i=0;i<len;i++){
			rStr.append(keyMap.get(String.valueOf(str.charAt(i))));
		}
		if(b==0l){
			b=uid/2;
		}
		String temp=String.valueOf(String.valueOf(b).hashCode());
		for(int i=0;i<temp.length();i++){
			rStr.append(hashKeyMap.get(String.valueOf(temp.charAt(i))));
		}
		return rStr.toString();
	}
%>
<%
	if(pageMap.get(request.getRequestURI())!=null){
		String uidStr=confuseUid(userid);
		StringBuffer  url = new StringBuffer(request.getScheme()+"://"+ request.getServerName()+request.getRequestURI());
		 if(request.getQueryString()!=null && !"".equals(request.getQueryString())){
			 url.append("?"+request.getQueryString());
			if(request.getQueryString().indexOf("&"+uidStr)==-1 && request.getQueryString().indexOf(uidStr)==-1){
				 url.append("&"+uidStr);
				 response.sendRedirect(url.toString());
				 return;
			}
		 }else{
			 url.append("?"+uidStr);
			 response.sendRedirect(url.toString());
			 return;
		 }
	}
%>
